$(window).load(function() {
    $('#slider').nivoSlider({
        effect: 'random', // Specify sets like: 'fold,fade,sliceDown'
        slices: 15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed: 500, // Slide transition speed
        pauseTime: 3000, // How long each slide will show
        startSlide: 0, // Set starting Slide (0 index)
        directionNav: false, // Next & Prev navigation
        //controlNav: false, // 1,2,3... navigation
        controlNavThumbs: false, // Use thumbnails for Control Nav
        pauseOnHover: true, // Stop animation while hovering
        manualAdvance: false, // Force manual transitions
        prevText: 'Prev', // Prev directionNav text
        nextText: 'Next', // Next directionNav text
        randomStart: false, // Start on a random slide
        beforeChange: function() {
        }, // Triggers before a slide transition
        afterChange: function() {
        }, // Triggers after a slide transition
        slideshowEnd: function() {
        }, // Triggers after all slides have been shown
        lastSlide: function() {
        }, // Triggers when last slide is shown
        afterLoad: function() {
        }         // Triggers when slider has loaded
    });
});

$(document).ready(function() {

    $('.questions .question').click(function() {
        var $this = $(this).parent();
        if ($this.hasClass('open')) {
            $this.removeClass('open');
        } else {
            $this.addClass('open');
            $this.siblings().removeClass('open');
        }


    });

    $(".various").fancybox({
        maxWidth: 800,
        maxHeight: 600,
        fitToView: false,
        width: '70%',
        height: '70%',
        autoSize: false,
        closeClick: false,
        openEffect: 'none',
        closeEffect: 'none'
    });

    $('.nav ul li').mouseenter(function() {
        $(this).find('ul').slideDown(300);
    }).mouseleave(function() {
        $(this).find('ul').slideUp('fast');
    });
    
    
    $('.pl-list').find('li.active').closest('ul').closest('li').addClass('active parent').closest('ul').closest('li').addClass('active grand');
    $('.header-action .btn-group').hover(function(){
        $(this).addClass('open');
    });
    $('.header-action .btn-group').blur(function(){
        $(this).removeClass('open');
    });
});

function loadAjax(data, type, fn, success) {
    $.ajax({
        url: fn,
        type: type,
        data: data,
        dataType: 'JSON',
        success: success,
        error: function(errorThrown) {
            console.log(errorThrown);
        }

    });
}

function changeLang(lang) {
    var url = baseUrl + 'switch-lang.php';
    loadAjax('lang=' + lang, 'GET', url, function(resp) {
        location.reload();
    });
}

function search(obj){
    var val = $(obj).closest('.input-group').find('.search-input').val();
    if(!val){return false;}
    window.location = baseUrl+'search-result/'+val+'.html';
}
